import allure
from selenium.common import NoSuchElementException
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By

from base.base_page import BasePage
from utils.logger import logger


class HomePage(BasePage):
    # 侧边栏订单管理的下拉框状态
    ORDER_FORM_STATUS = 0
    _ORDER_FORM = (By.XPATH, "//span[text()='订单管理']")
    _ORDER_LIST = (By.XPATH, "//*[text()='订单列表']")
    _ORDER_ENTRY = (By.XPATH, "//*[text()='订单录入']")

    @allure.step("打开订单管理下拉框")
    def open_order_form(self):
        logger.info('打开订单管理下拉框')
        # 如果已经打开了，那就直接返回
        if self.ORDER_FORM_STATUS == 0:
            self.ORDER_FORM_STATUS = 1
        else:
            return
        self.find_and_click(self._ORDER_FORM)
        return

    @allure.step("前往订单列表页面")
    def goto_order_form_page(self):
        logger.info("前往订单列表页面")
        self.open_order_form()
        self.find_and_click(self._ORDER_LIST)
        from page.orderform_page import OrderformPage
        return OrderformPage(self._driver)

    @allure.step("前往订单录入页面")
    def goto_order_entry(self):
        logger.info("前往订单录入页面")
        self.open_order_form()
        self.find_and_click(self._ORDER_ENTRY)
        from page.order_entry_page import OrderEntryPage
        return OrderEntryPage(self._driver)



